<template>
    <div>
        <group>
            <radio fill-mode fill-label="金额" fill-placeholder="元" v-model="chargeVal" :options="chargeOps" @on-change="onCharge"></radio>
        </group>
        <div style="padding:15px;">
            <x-button type="primary" @click.native="doCharge()">微信支付</x-button>
        </div>
    </div>
</template>
<script>
import {
    Radio,
    Group,
    XButton
} from 'vux'

import {
    mapState,
    mapActions
} from 'vuex'
import api from '../api';

export default {
    components: {
        Radio,
        Group,
        XButton
    },
    methods: {
        onCharge(val) {
            console.log('change:', val)
        },
        doCharge() {
            console.log("充值:" + this.chargeVal);
            let _this = this;
            if (this.chargeVal <= 0) {
                _this.$vux.toast.show({
                    text: "请选择金额",
                    type: 'warn'
                })
                return;
            }
            api.order({
                order_amount: this.chargeVal,
                subject: `${this.chargeVal}时币`
            }).then(data => {
                if(data.errno !=0) return this.$vux.toast.show({text: data.errmsg ,type: 'warn'});
				
				WeixinJSBridge.invoke('getBrandWCPayRequest', data.data.data.credential.wx_pub, function(res) {
					if (res.err_msg == "get_brand_wcpay_request:ok") {
						_this.$vux.toast.show({
							text: "支付成功",
							type: 'success'
						})
						this.$router.back(-1); //_this.go("m_mine");
					} else {
						_this.$vux.toast.show({
							text: "支付失败",
							type: 'warn'
						})
					}
				});
                
            })
        }
    },
    data() {
        return {
            chargeVal: 0,
            chargeOps: [{
                key: '1',
                value: ' 10时币  =  1元'
            }, {
                key: '5',
                value: ' 50时币  =  5元'
            }, {
                key: '10',
                value: '100时币 = 10元'
            }, {
                key: '20',
                value: '200时币 = 20元'
            }, {
                key: '50',
                value: '500时币 = 50元'
            }, {
                key: '100',
                value: '1000时币=100元'
            }]
        }
    }
}
</script>
